//
//  PCPointsManager.m
//  PromotionCode
//
//  Created by uuu9 on 2017/11/29.
//  Copyright © 2017年 My. All rights reserved.
//

#import "PCPointsManager.h"
#import "PCEarnPointsModel.h"
#import "PCPointsHistoryModel.h"
#import "PCEarnPointsRateModel.h"
#import "PCPointsDescModel.h"

@implementation PCPointsManager

+(void)getPointsRateTypeWithCompletionHandle:(void (^)(PCEarnPointsRateModel *, NSError *))complete{
    [self GET:[NSString stringWithFormat:@"%@%@",Api_URL,kPointsRate]
   parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    PCEarnPointsRateModel *model = [PCEarnPointsRateModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(model,error);
}];
    
}

+(void)getPointsHistoryWithUserID:(NSString *)uid andSessionID:(NSString *)sessionid andCompletionHandle:(void (^)(PCPointsHistoryModel *, NSError *))complete{
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,kPointsHistory]
           parameters:[NSString stringWithFormat:@"userid=%@&sessionid=%@",uid,sessionid]
    completionHandler:^(id responseObj, NSError *error) {
        PCPointsHistoryModel *model = [PCPointsHistoryModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
    
}


+(void)earnPointsWithUserID:(NSString *)uid andSessionID:(NSString *)sessionid andMoney:(NSString *)money andRateID:(NSString *)rateID andCompletionHandle:(void (^)(PCEarnPointsModel *, NSError *))complete{
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,kEarnPoints]
           parameters:[NSString stringWithFormat:@"userid=%@&sessionid=%@&money=%@&month_id=%@",uid,sessionid,money,rateID]
    completionHandler:^(id responseObj, NSError *error) {
        PCEarnPointsModel *model = [PCEarnPointsModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
    
}

+ (void)pointsDescWithCompletionHandle:(void (^)(PCPointsDescModel *, NSError *))complete{
    [self GET:[NSString stringWithFormat:@"%@%@",Api_URL,kPointsDesc]
           parameters:nil
    completionHandler:^(id responseObj, NSError *error) {
        PCPointsDescModel *model = [PCPointsDescModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
    
}


@end
